package ca.liu.study.springdata.jpa.domain.superclass;

import java.util.Objects;

import javax.persistence.MappedSuperclass;

import com.google.common.base.Objects.ToStringHelper;

@MappedSuperclass
public class People extends IdentityIdDomain<Long> {

	private String firstName;
	private String lastName;
	private String email;

	public People () {
	}
	
	public People (String firstName, String lastName, String email) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
	}
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	public String toString() {
		return toStringHelper().toString();
	}
	
    public boolean equals(Object obj) {
    	//check id equal
    	if(!super.equals(obj)) {
    		return false;
    	}
    	
    	//check email equal
        if (obj instanceof People) {
        	People other = (People) obj;
            return Objects.equals(getEmail(), other.getEmail());
        }
        return false;
    }

	protected ToStringHelper toStringHelper() {
		return super.toStringHelper()
				.add("name", firstName.concat(" ").concat(lastName))
				.add("email", email);
	}
}
